/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Created on 20.11.2003 by RST
// $Id: level_locals_t.java,v 1.2 2004/08/20 21:29:57 salomo Exp $
using System;
using Lib = Suake2.UI.util.Lib;
using QuakeFile = Suake2.UI.util.QuakeFile;
namespace Suake2.UI.game
{
	
	public class level_locals_t
	{
		
		//	this structure is cleared as each map is entered
		//	it is read/written to the level.sav file for savegames
		//
		public int framenum;
		public float time;
		
		public System.String level_name = ""; // the descriptive name (Outer Base, etc)
		public System.String mapname = ""; // the server name (base1, etc)
		public System.String nextmap = ""; // go here when fraglimit is hit
		
		// intermission state
		public float intermissiontime; // time the intermission was started
		public System.String changemap;
		public bool exitintermission;
		public float[] intermission_origin = new float[]{0, 0, 0};
		public float[] intermission_angle = new float[]{0, 0, 0};
		
		public edict_t sight_client; // changed once each frame for coop games
		
		public edict_t sight_entity;
		public int sight_entity_framenum;
		
		public edict_t sound_entity;
		public int sound_entity_framenum;
		
		public edict_t sound2_entity;
		public int sound2_entity_framenum;
		
		public int pic_health;
		
		public int total_secrets;
		public int found_secrets;
		
		public int total_goals;
		public int found_goals;
		
		public int total_monsters;
		public int killed_monsters;
		
		public edict_t current_entity; // entity running from G_RunFrame
		public int body_que; // dead bodies
		
		public int power_cubes; // ugly necessity for coop
		
		/// <summary>Writes the levellocales to the file.</summary>
		public virtual void  write(QuakeFile f)
		{
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Int32) framenum);
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Single) time);
			f.writeString(level_name);
			f.writeString(mapname);
			f.writeString(nextmap);
			System.IO.BinaryWriter temp_BinaryWriter3;
			temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter3.Write((System.Single) intermissiontime);
			f.writeString(changemap);
			System.IO.BinaryWriter temp_BinaryWriter4;
			temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter4.Write((System.Boolean) exitintermission);
			f.writeVector(intermission_origin);
			f.writeVector(intermission_angle);
			f.writeEdictRef(sight_client);
			
			f.writeEdictRef(sight_entity);
			System.IO.BinaryWriter temp_BinaryWriter5;
			temp_BinaryWriter5 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter5.Write((System.Int32) sight_entity_framenum);
			
			f.writeEdictRef(sound_entity);
			System.IO.BinaryWriter temp_BinaryWriter6;
			temp_BinaryWriter6 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter6.Write((System.Int32) sound_entity_framenum);
			f.writeEdictRef(sound2_entity);
			System.IO.BinaryWriter temp_BinaryWriter7;
			temp_BinaryWriter7 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter7.Write((System.Int32) sound2_entity_framenum);
			
			System.IO.BinaryWriter temp_BinaryWriter8;
			temp_BinaryWriter8 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter8.Write((System.Int32) pic_health);
			
			System.IO.BinaryWriter temp_BinaryWriter9;
			temp_BinaryWriter9 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter9.Write((System.Int32) total_secrets);
			System.IO.BinaryWriter temp_BinaryWriter10;
			temp_BinaryWriter10 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter10.Write((System.Int32) found_secrets);
			
			System.IO.BinaryWriter temp_BinaryWriter11;
			temp_BinaryWriter11 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter11.Write((System.Int32) total_goals);
			System.IO.BinaryWriter temp_BinaryWriter12;
			temp_BinaryWriter12 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter12.Write((System.Int32) found_goals);
			System.IO.BinaryWriter temp_BinaryWriter13;
			temp_BinaryWriter13 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter13.Write((System.Int32) total_monsters);
			System.IO.BinaryWriter temp_BinaryWriter14;
			temp_BinaryWriter14 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter14.Write((System.Int32) killed_monsters);
			
			f.writeEdictRef(current_entity);
			System.IO.BinaryWriter temp_BinaryWriter15;
			temp_BinaryWriter15 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter15.Write((System.Int32) body_que); // dead bodies
			System.IO.BinaryWriter temp_BinaryWriter16;
			temp_BinaryWriter16 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter16.Write((System.Int32) power_cubes); // ugly necessity for coop
			
			// rst's checker :-)		
			System.IO.BinaryWriter temp_BinaryWriter17;
			temp_BinaryWriter17 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter17.Write((System.Int32) 4711);
		}
		
		/// <summary>Reads the level locals from the file. </summary>
		public virtual void  read(QuakeFile f)
		{
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			framenum = temp_BinaryReader.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			time = temp_BinaryReader2.ReadSingle();
			level_name = f.readString();
			mapname = f.readString();
			nextmap = f.readString();
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			intermissiontime = temp_BinaryReader3.ReadSingle();
			changemap = f.readString();
			System.IO.BinaryReader temp_BinaryReader4;
			temp_BinaryReader4 = new System.IO.BinaryReader(f);
			temp_BinaryReader4.BaseStream.Position = f.Position;
			exitintermission = temp_BinaryReader4.ReadBoolean();
			intermission_origin = f.readVector();
			intermission_angle = f.readVector();
			sight_client = f.readEdictRef();
			
			sight_entity = f.readEdictRef();
			System.IO.BinaryReader temp_BinaryReader5;
			temp_BinaryReader5 = new System.IO.BinaryReader(f);
			temp_BinaryReader5.BaseStream.Position = f.Position;
			sight_entity_framenum = temp_BinaryReader5.ReadInt32();
			
			sound_entity = f.readEdictRef();
			System.IO.BinaryReader temp_BinaryReader6;
			temp_BinaryReader6 = new System.IO.BinaryReader(f);
			temp_BinaryReader6.BaseStream.Position = f.Position;
			sound_entity_framenum = temp_BinaryReader6.ReadInt32();
			sound2_entity = f.readEdictRef();
			System.IO.BinaryReader temp_BinaryReader7;
			temp_BinaryReader7 = new System.IO.BinaryReader(f);
			temp_BinaryReader7.BaseStream.Position = f.Position;
			sound2_entity_framenum = temp_BinaryReader7.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader8;
			temp_BinaryReader8 = new System.IO.BinaryReader(f);
			temp_BinaryReader8.BaseStream.Position = f.Position;
			pic_health = temp_BinaryReader8.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader9;
			temp_BinaryReader9 = new System.IO.BinaryReader(f);
			temp_BinaryReader9.BaseStream.Position = f.Position;
			total_secrets = temp_BinaryReader9.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader10;
			temp_BinaryReader10 = new System.IO.BinaryReader(f);
			temp_BinaryReader10.BaseStream.Position = f.Position;
			found_secrets = temp_BinaryReader10.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader11;
			temp_BinaryReader11 = new System.IO.BinaryReader(f);
			temp_BinaryReader11.BaseStream.Position = f.Position;
			total_goals = temp_BinaryReader11.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader12;
			temp_BinaryReader12 = new System.IO.BinaryReader(f);
			temp_BinaryReader12.BaseStream.Position = f.Position;
			found_goals = temp_BinaryReader12.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader13;
			temp_BinaryReader13 = new System.IO.BinaryReader(f);
			temp_BinaryReader13.BaseStream.Position = f.Position;
			total_monsters = temp_BinaryReader13.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader14;
			temp_BinaryReader14 = new System.IO.BinaryReader(f);
			temp_BinaryReader14.BaseStream.Position = f.Position;
			killed_monsters = temp_BinaryReader14.ReadInt32();
			
			current_entity = f.readEdictRef();
			System.IO.BinaryReader temp_BinaryReader15;
			temp_BinaryReader15 = new System.IO.BinaryReader(f);
			temp_BinaryReader15.BaseStream.Position = f.Position;
			body_que = temp_BinaryReader15.ReadInt32(); // dead bodies
			System.IO.BinaryReader temp_BinaryReader16;
			temp_BinaryReader16 = new System.IO.BinaryReader(f);
			temp_BinaryReader16.BaseStream.Position = f.Position;
			power_cubes = temp_BinaryReader16.ReadInt32(); // ugly necessity for coop		
			
			// rst's checker :-)
			System.IO.BinaryReader temp_BinaryReader17;
			temp_BinaryReader17 = new System.IO.BinaryReader(f);
			temp_BinaryReader17.BaseStream.Position = f.Position;
			if (temp_BinaryReader17.ReadInt32() != 4711)
				System.Console.Out.WriteLine("error in reading level_locals.");
		}
	}
}